//
//  WBHomeViewController.swift
//  YLWeibo
//
//  Created by 楊亜玲 on 16/11/9.
//  Copyright © 2016年 楊亜玲. All rights reserved.
//

import UIKit

let cellId = "cellId"

class WBHomeViewController: WBBaseViewController {
    
    lazy var statusList = [String]()

    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    override func loadNewData() {
        // 模拟 延迟 加载数据 dispatch_after
        DispatchQueue.main.asyncAfter(deadline: .now() + 1){
            
            for i in 0..<15{
                if self.isPullUp{
                    self.statusList.append("上拉" + i.description)
                }else{
                    self.statusList.insert(i.description, at: 0)
                }
            }
            // 结束刷新控件
            self.refreshControl?.endRefreshing()
            
            self.isPullUp = false
            
        // 刷新tableView
            self.tableView?.reloadData()
        }
    }
    
    func showFriends()  {

        let vc = WBDemoViewController()
        // push到新页面
        navigationController?.pushViewController(vc, animated: true)
    }
}

extension WBHomeViewController{
    /// 重写父类方法
    override func setupUI() {
        super.setupUI()
        
        // 设置导航栏按钮
        naviItem.leftBarButtonItem = UIBarButtonItem(title: "好友", fontSize: 16, target: self, action: #selector(showFriends))
        
        // 注册原型cell
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
        
    }
}

extension WBHomeViewController{
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        cell.textLabel?.text = statusList[indexPath.row]
        return cell
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count
    }
}
